Javascript functions return lines of function code or "{[native code]}," what am I doing wrong?

Posted by DavidR on Stack Overflow See other posts from Stack Overflow or by DavidR
Published on 2010-05-12T16:11:01Z Indexed on 2010/05/12 16:14 UTC
Read the original article Hit count: 278

I am writing some code to find the user selection in a contenteditable div, I'm taking my code from this quirksmode article.

function findSelection(){
  var userSelection;
  if (window.getSelection) {userSelection = window.getSelection;} 
   else if (document.selection){userSelection = document.selection.createRange();} // For microsoft
  if (userSelection.text){return userSelection.text} //for Microsoft
   else {return userSelection} 
  } 

I'm testing it in Chrome and Firefox, if I do an alert(userSelection) within the function or an alert(findSelection();) outside the function, it returns function getSelection() {[native code]}. If I do console.log(findSelection();) it gives me getSelection(). Is there something I've done wrong?

© Stack Overflow or respective owner

Related posts about contenteditable

Related posts about getselection